package net.lanelife.casino.caipiao.repository.api;

import net.lanelife.casino.caipiao.entity.UserLayer;
import net.lanelife.casino.common.repository.support.GenericRepository;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface IUserLayerRepository extends GenericRepository<UserLayer, Integer> {

	public UserLayer findByIsDefault(Boolean isDefault);
	
	@Modifying
	@Query("UPDATE UserLayer l SET l.layerUsers=(SELECT COUNT(u) FROM User u WHERE u.layerId=l.id)")
	public void countUsers();
	
	@Modifying
	@Query("UPDATE User SET layerId=:destination WHERE layerId=:source")
	public void migrateUsers(@Param("source") Integer source, @Param("destination") Integer destination);
	
}
